package gold.digger;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC1337 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int[] kWeakestRows(int[][] mat, int k) {
            int[] ans = new int[k];
            List<Integer> lines = new ArrayList<>();
            for (int i = 0; i < mat.length; i++)
                lines.add(binarySearch(mat[i]) * 100 + i);
            Collections.sort(lines);
            for (int i = 0; i < k; i++)
                ans[i] = lines.get(i) % 100;
            return ans;
        }

        public int binarySearch(int[] nums) {
            int left = 0, right = nums.length;
            while (left < right) {
                int mid = left + (right - left) / 2;
                if (nums[mid] == 0) {
                    right = mid;
                } else {
                    left = mid + 1;
                }
            }
            return left;
        }
    }


    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC1337 an = new LC1337();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
